import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/core/utils/interface.dart';
import 'package:enterprise_v6_app/app/data/entities/closure/closure_appointment_entity.dart';

/// 预约审核-基本信息
class ReviewBasicInfo extends StatelessWidget {
  const ReviewBasicInfo({required this.type,required this.item, super.key});

  /// 0: 人员  1&2: 车辆
  final int type;

  /// 详情
  final ClosureAppointmentEntity item;

  // 性别: 0.男 1.女 2.保密
  String _sex(int i) {
    switch (i) {
      case 0:
        return '男';
      case 1:
        return '女';
      case 2:
        return '保密';
      default:
        return '';
    }
  }

  // 100.后台管理账号 1.企业人员账号 2.园区账号 3.政府人员账号 4:临时访客 5:第三方单位人员 6:其他
  String _personType(String type) {
    switch (type) {
      case '100':
        return '后台管理账号';
      case '1':
        return '企业人员账号';
      case '2':
        return '园区账号';
      case '3':
        return '政府人员账号';
      case '4':
        return '临时访客';
      case '5':
        return '第三方单位人员';
      case '6':
        return '其他';
      default:
        return '';
    }
  }

  /// 车辆类型
  /// 1:普货车辆 2:社会车辆 3:小型车辆 4:应急车辆 5:其他
  String _carType(String type) {
    switch (type) {
      case '1':
        return '普货车辆';
      case '2':
        return '社会车辆';
      case '3':
        return '小型车辆';
      case '4':
        return '应急车辆';
      case '5':
        return '其他';
      default:
        return '';
    }
  }
  /// 信息列表
  Widget _widget() {
    return Column(
      children: [
        Column(
          children: type == 0 ? [
            _buildBasicInfoItem(
              '人员类型',
              _personType(item.type),
            ),
            _buildBasicInfoItem(
              '性别',
              _sex(item.sex),
            ),
            _buildBasicInfoItem(
              '证件号码',
              item.idNo,
            ),
            _buildBasicInfoItem(
              '所属单位',
              item.affiliatedUnit,
            ),
            _buildBasicInfoItem(
              '职位名称',
              item.title,
            ),
            _buildBasicInfoItem(
              '专业',
              item.speciality,
            ),
          ] : [
            _buildBasicInfoItem(
              '证件号码',
              item.idNo,
            ),
            _buildBasicInfoItem(
              '车牌号码',
              item.licensePlate,
            ),
            _buildBasicInfoItem(
              '车辆类型',
              _carType(item.carType),
            ),
            _buildBasicInfoItem(
              '所属企业',
              item.affiliatedUnit,
            ),

          ],
        ),
        _buildBasicInfoItem(
          '对接人',
          item.contactPerson,
        ),
        _buildBasicInfoItem(
          '对接人电话',
          item.personToPersonPhoneNumber,
        ),
        _buildBasicInfoItem(
          '预计到访时间',
          item.startDate,
        ),
        _buildBasicInfoItem(
          '来访事由',
          item.reasonForVisit,
        ),
      ],
    );
  }

  /// 基本信息
  Widget _buildBasicInfoItem(
    String key,
    String? val, {
    bool isRequired = false,
    bool isPic = false,
  }) {
    return Padding(
      padding: EdgeInsets.symmetric(horizontal: 37.w, vertical: 6.w),
      child: Row(
        children: [
          SizedBox(
            width: 120.w,
            child: Row(
              mainAxisAlignment: MainAxisAlignment.start,
              children: [
                if (isRequired)
                  Text(
                    '*',
                    style: TextStyle(
                      fontSize: 13.sp,
                      color: Colors.red,
                    ),
                    textAlign: TextAlign.center,
                  ),
                Text(
                  key,
                  style: TextStyle(
                    fontSize: 14.sp,
                    color: const Color(0xFF7C7D93),
                  ),
                )
              ],
            ),
          ),
          isPic
              ? SizedBox(
                  height: 77.w,
                  width: 77.w,
                  child: Image.network(val!),
                )
              : Expanded(
                  child: Text(
                    val ?? '',
                    style: TextStyle(
                      fontSize: 12.sp,
                      color: const Color(0xFF495061),
                    ),
                  ),
                ),
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.white,
      child: Stack(
        children: [
          Column(
            children: [
              Container(
                height: 38.w,
                width: double.infinity,
                color: AppColors.bg_color_grey,
                alignment: Alignment.centerLeft,
                padding: EdgeInsets.only(left: 16.w),
                child: Text(
                  '基本信息',
                  style: TextStyle(
                    fontSize: 12.sp,
                    color: AppColors.text_grey,
                  ),
                ),
              ),
              Container(
                height: 2.w,
                color: AppColors.blue_button,
              ),
              Container(
                height: 64.w,
                color: const Color(0xFFF4F7FF),
                child: Row(
                  children: [
                    AppGaps.hGap30,
                    Visibility(
                      visible: type == 0,
                      child: Row(
                        children: [
                          ClipRRect(
                            borderRadius: BorderRadius.circular(4),
                            child: item.photoUrl != '' ? Image.network(
                              item.photoUrl.startsWith('http') ? item.photoUrl : Interface.fileUrl + item.photoUrl,
                              width: 45.w,
                              height: 45.w,
                              fit: BoxFit.cover,
                            ) : Container(
                              width: 45.w,
                              height: 45.w,
                              color: Colors.grey[300],
                            ),
                          ),
                          AppGaps.hGap20,
                        ],
                      ),
                    ),
                    Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text(
                          type == 0 ? '人员姓名：${item.name}' : '驾驶员姓名：${item.name}',
                          style: TextStyle(
                            fontSize: 16.sp,
                            fontWeight: FontWeight.w500,
                          ),
                        ),
                        AppGaps.vGap4,
                        Text(
                          '联系方式: ${item.visitorTelephone}',
                          style: TextStyle(
                            fontSize: 13.sp,
                            color: const Color(0xFF3F425B),
                          ),
                        ),
                      ],
                    ),
                  ],
                ),
              ),
              Container(
                height: 1.w,
                color: AppColors.divider_color_blue,
              ),
              AppGaps.vGap14,
              _widget(),
            ],
          ),
          Positioned(
            top: 80,
            right: 20,
            child: Visibility(visible: item.appointmentStatus == 2, child: SvgPicture.asset(AppImages.icon_reject)),
          )
        ],
      ),
    );
  }
}
